package com.vecspace.dayu.code.ui.pojo;

import java.util.Date;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.vecspace.data.model.IdEntity;
import com.vecspace.data.model.RowMapper;
import com.vecspace.dayu.code.pojo.DataColumn;
import com.vecspace.dicttable.DictAll;

import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.Polymorphism;
import org.hibernate.annotations.PolymorphismType;
import org.hibernate.annotations.Type;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/** DAYU-页面数据表格列
 * @author wanghua
 */
@Entity
@Polymorphism(type = PolymorphismType.EXPLICIT)
@Table(name = "DAYU_CODE_UI_DATA_GRID_COLUMN")
public class DataGridColumn implements IdEntity, java.io.Serializable {

	private static final long serialVersionUID = -6614473411763205677L;
	public DataGridColumn(){
	}
	
	private Long id;
	/**逻辑ID*/
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "ID")
	public Long getId(){
		return id;
	}
	/**逻辑ID*/
	public void setId(Long value){
		this.id = value;
	}

	private Long datagridId;
	/**表格ID*/
	@Column(name = "DATAGRID_ID")
	public Long getDatagridId(){
		return datagridId;
	}
	/**表格ID*/
	public void setDatagridId(Long value){
		this.datagridId = value;
	}

	private Long columnId;
	/**字段ID*/
	@Column(name = "COLUMN_ID")
	public Long getColumnId(){
		return columnId;
	}
	/**字段ID*/
	public void setColumnId(Long value){
		this.columnId = value;
	}

	private String columnLabel;
	/**表头*/
	@Column(name = "COLUMN_LABEL")
	public String getColumnLabel(){
		return columnLabel;
	}
	/**表头*/
	public void setColumnLabel(String value){
		this.columnLabel = value;
	}

	private String columnGroup;
	/**表头分组*/
	@Column(name = "COLUMN_GROUP")
	public String getColumnGroup(){
		return columnGroup;
	}
	/**表头分组*/
	public void setColumnGroup(String value){
		this.columnGroup = value;
	}

	private Integer columnWidth;
	/**列宽*/
	@Column(name = "COLUMN_WIDTH")
	public Integer getColumnWidth(){
		return columnWidth;
	}
	/**列宽*/
	public void setColumnWidth(Integer value){
		this.columnWidth = value;
	}

	private String cellTextType;

	public static String CellTextTypeCode = "DAYU-CODE-009";
	/**显示样式*/
	@Column(name = "CELL_TEXT_TYPE")
	public String getCellTextType(){
		return cellTextType;
	}
	/**显示样式*/
	public void setCellTextType(String value){
		this.cellTextType = value;
	}

	@Transient
	public String getCellTextTypeCaption(){
		return DictAll.getCachedItemName(CellTextTypeCode, cellTextType);
	}
	
	private String fontStyle;
	/**字体*/
	@Column(name = "FONT_STYLE")
	public String getFontStyle(){
		return fontStyle;
	}
	/**字体*/
	public void setFontStyle(String value){
		this.fontStyle = value;
	}

	private Boolean hyperlink;
	/**超链接*/
	@Column(name = "HYPERLINK")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getHyperlink(){
		return hyperlink;
	}
	/**超链接*/
	public void setHyperlink(Boolean value){
		this.hyperlink = value;
	}

	private String renderScript;
	/**自定义显示内容*/
	@Column(name = "RENDER_SCRIPT")
	public String getRenderScript(){
		return renderScript;
	}
	/**自定义显示内容*/
	public void setRenderScript(String value){
		this.renderScript = value;
	}

	private Boolean visibleStatus;
	/**显示状态*/
	@Column(name = "VISIBLE_STATUS")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getVisibleStatus(){
		return visibleStatus;
	}
	/**显示状态*/
	public void setVisibleStatus(Boolean value){
		this.visibleStatus = value;
	}

	private Boolean fixed;
	/**是否固定列*/
	@Column(name = "FIXED")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getFixed(){
		return fixed;
	}
	/**是否固定列*/
	public void setFixed(Boolean value){
		this.fixed = value;
	}

	private Boolean mergeCell;
	/**合并单元格*/
	@Column(name = "MERGE_CELL")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getMergeCell(){
		return mergeCell;
	}
	/**合并单元格*/
	public void setMergeCell(Boolean value){
		this.mergeCell = value;
	}

	private Boolean editAble;
	/**可编辑*/
	@Column(name = "EDIT_ABLE")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getEditAble(){
		return editAble;
	}
	/**可编辑*/
	public void setEditAble(Boolean value){
		this.editAble = value;
	}

	private String inputElementType;
	
	public static String InputElementTypeCode = "DAYU-CODE-011";
	/**编辑输入框类型*/
	@Column(name = "INPUT_ELEMENT_TYPE")
	public String getInputElementType(){
		return inputElementType;
	}
	/**编辑输入框类型*/
	public void setInputElementType(String value){
		this.inputElementType = value;
	}

	@Transient
	public String getInputElementTypeCaption(){
		return DictAll.getCachedItemName(InputElementTypeCode, inputElementType);
	}
	/**下拉菜单 0否 1是*/
	private Boolean editMenu;
	/**下拉菜单 0否 1是*/
	@Column(name = "EDIT_MENU")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getEditMenu(){
		return editMenu;
	}
	/**下拉菜单 0否 1是*/
	public void setEditMenu(Boolean value){
		this.editMenu = value;
	}
	
	private String aggregateFunc;
	public static String AggregateFuncCode = "DAYU-CODE-022";
	/**聚合函数*/
	@Column(name = "AGGREGATE_FUNC")
	public String getAggregateFunc() {
		return aggregateFunc;
	}
	/**聚合函数*/
	public void setAggregateFunc(String aggregateFunc) {
		this.aggregateFunc = aggregateFunc;
	}
	@Transient
	public String getAggregateFuncCaption(){
		return aggregateFunc;//不需要翻译为中文
//		if(StringUtils.isNoneBlank(aggregateFunc)) {
//			String[] funcs = aggregateFunc.split(",");
//			String funcLabel = "";
//			for(int i = 0; i < funcs.length; i++) {
//				if(i == (funcs.length -1)) {
//					funcLabel += DictAll.getCachedItemName(AggregateFuncCode, funcs[i]);
//				}else {
//					funcLabel += DictAll.getCachedItemName(AggregateFuncCode, funcs[i]) + ",";
//				}
//			}
//			return funcLabel;
//		}
//		return null;
	}
	
	private Boolean aggregateGroup;
	@Column(name = "AGGREGATE_GROUP")@Type(type="org.hibernate.type.NumericBooleanType")
	/**是否分组字段 0否 1是*/
	public Boolean getAggregateGroup() {
		return aggregateGroup;
	}
	/**是否分组字段 0否 1是*/
	public void setAggregateGroup(Boolean aggregateGroup) {
		this.aggregateGroup = aggregateGroup;
	}
	
	/**是否为查询项,0否，1是*/
	private Boolean isQueryField;
	/**是否为查询项,0否，1是*/
	@Column(name = "IS_QUERY_FIELD")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getQueryField() {
		return isQueryField;
	}
	/**是否为查询项,0否，1是*/
	public void setQueryField(Boolean queryField) {
		isQueryField = queryField;
	}
	
	private String querySqlOperator;

	public static String QuerySqlOperatorCode = "DAYU-CODE-016";
	
	/**查询项条件匹配类型*/
	@Column(name = "QUERY_SQL_OPERATOR")
	public String getQuerySqlOperator() {
		return querySqlOperator;
	}
	/**查询项条件匹配类型*/
	public void setQuerySqlOperator(String querySqlOperator) {
		this.querySqlOperator = querySqlOperator;
	}

	@Transient
	public String getQuerySqlOperatorCaption(){
		return DictAll.getCachedItemName(QuerySqlOperatorCode, querySqlOperator);
	}
	public static String showStatusCode = "DAYU-CODE-018";
	private Boolean queryVisibleStatus;
	/**查询项显示状态,0默认不显示，1默认显示，3始终显示*/
	@Column(name = "QUERY_VISIBLE_STATUS")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getQueryVisibleStatus() {
		return queryVisibleStatus;
	}
	/**查询项显示状态,0默认不显示，1默认显示，3始终显示*/
	public void setQueryVisibleStatus(Boolean queryVisibleStatus) {
		this.queryVisibleStatus = queryVisibleStatus;
	}


	private String queryInputElementType;
	public static final String QueryInputElementTypeCode = "DAYU-CODE-012";
	
	/**查询项输入框类型*/
	@Column(name = "QUERY_INPUT_ELEMENT_TYPE")
	public String getQueryInputElementType() {
		return queryInputElementType;
	}
	/**查询项输入框类型*/
	public void setQueryInputElementType(String queryInputElementType) {
		this.queryInputElementType = queryInputElementType;
	}
	@Transient
	public String getQueryInputElementTypeCaption(){
		return DictAll.getCachedItemName(QueryInputElementTypeCode, queryInputElementType);
	}

	private Boolean queryRequired;
	/**查询项是否必填，0否，1是*/
	@Column(name = "QUERY_REQUIRED")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getQueryRequired() {
		return queryRequired;
	}
	/**查询项是否必填，0否，1是*/
	public void setQueryRequired(Boolean queryRequired) {
		this.queryRequired = queryRequired;
	}
	
	private Boolean queryMultiValue;
	/**查询项是否可多选，0否，1是*/
	@Column(name = "QUERY_MULTI_VALUE")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getQueryMultiValue() {
		return queryMultiValue;
	}
	/**查询项是否可多选，0否，1是*/
	public void setQueryMultiValue(Boolean queryMultiValue) {
		this.queryMultiValue = queryMultiValue;
	}
	
	
	
	private Integer ordnum;
	/**顺序号*/
	@Column(name = "ORDNUM")
	public Integer getOrdnum(){
		return ordnum;
	}
	/**顺序号*/
	public void setOrdnum(Integer value){
		this.ordnum = value;
	}

	private Date createTime;
	/**记录创建时间*/
	@JsonIgnore(true)
	@Column(name = "CREATE_TIME")
	public Date getCreateTime(){
		return createTime;
	}
	/**记录创建时间*/
	public void setCreateTime(Date value){
		this.createTime = value;
	}
	@Transient
	@JsonIgnore(true)
	public String getCreateTimeStr(){
		if(createTime == null){
			return "";
		}
		String exp = "yyyy-MM-dd";
		String timestr = new java.text.SimpleDateFormat(exp).format(createTime);
		return timestr;
	}

	private String createUser;
	/**记录创建人ID*/
	@Column(name = "CREATE_USER")
	public String getCreateUser(){
		return createUser;
	}
	/**记录创建人ID*/
	public void setCreateUser(String value){
		this.createUser = value;
	}

	
	public void parseFrom(Map<String, Object> row){
		RowMapper rowMapper = new RowMapper(row);
		this.id = rowMapper.getLong("ID");
		this.datagridId = rowMapper.getLong("DATAGRID_ID");
		this.columnId = rowMapper.getLong("COLUMN_ID");
		this.columnLabel = rowMapper.getString("COLUMN_LABEL");
		this.columnGroup = rowMapper.getString("COLUMN_GROUP");
		this.columnWidth = rowMapper.getInteger("COLUMN_WIDTH");
		this.cellTextType = rowMapper.getString("CELL_TEXT_TYPE");
		this.fontStyle = rowMapper.getString("FONT_STYLE");
		this.hyperlink = rowMapper.getBoolean("HYPERLINK");
		this.renderScript = rowMapper.getString("RENDER_SCRIPT");
		this.visibleStatus = rowMapper.getBoolean("VISIBLE_STATUS");
		this.fixed = rowMapper.getBoolean("FIXED");
		this.mergeCell = rowMapper.getBoolean("MERGE_CELL");
		this.editAble = rowMapper.getBoolean("EDIT_ABLE");
		this.inputElementType = rowMapper.getString("INPUT_ELEMENT_TYPE");
		this.editMenu = rowMapper.getBoolean("EDIT_MENU");
		this.aggregateFunc = rowMapper.getString("AGGREGATE_FUNC");
		this.aggregateGroup = rowMapper.getBoolean("AGGREGATE_GROUP");
		this.isQueryField = rowMapper.getBoolean("IS_QUERY_FIELD");
		this.querySqlOperator = rowMapper.getString("QUERY_SQL_OPERATOR");
		this.queryVisibleStatus = rowMapper.getBoolean("QUERY_VISIBLE_STATUS");
		this.queryInputElementType = rowMapper.getString("QUERY_INPUT_ELEMENT_TYPE");
		this.queryRequired = rowMapper.getBoolean("QUERY_REQUIRED");
		this.queryMultiValue = rowMapper.getBoolean("QUERY_MULTI_VALUE");
		this.ordnum = rowMapper.getInteger("ORDNUM");
		this.createTime = rowMapper.getDate("CREATE_TIME");
		this.createUser = rowMapper.getString("CREATE_USER");
	}
	
	private DataColumn column;

	@Transient
	@JsonIgnore
	public DataColumn getColumn() {
		return column;
	}
	public void setColumn(DataColumn column) {
		this.column = column;
	}

	@Override
	public boolean equals(Object obj) {
		if(obj == null)return false;
		if(id == null)return false;
		DataGridColumn other = (DataGridColumn)obj;
		return id.equals(other.id);
	}

	@Override
	public int hashCode() {
		if(id == null)return 0;
		return id.hashCode();
	}
}
